package cn.dyp.com.logprint.action;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;

import cn.dyp.com.logprint.ServerApp;
import cn.dyp.com.logprint.util.Util;


/**
 * @author zongbingwu 获取所有传感器阀值的请求处理类
 */
public class GetConfigAction extends BaseAction {
	// action name
	public static final String TAG = "getConfig";

	private Context context;

	public GetConfigAction(Context context) {
		this.context = context;
		logObj = "All Sensor";
	}

	@Override
	protected String jasonPorcess(String param) {
		JSONObject jsonResponse = new JSONObject();
		try {
			// 获取告警范围请求
			ServerApp app = (ServerApp) context;
			jsonResponse.put("minAirTemperature", app.getMinAirTemperature());// 空气温度最小值
			jsonResponse.put("maxAirTemperature", app.getMaxAirTemperature());// 空气温度最大值
			jsonResponse.put("minAirHumidity", app.getMinAirHumidity());// 空气湿度最小值
			jsonResponse.put("maxAirHumidity", app.getMaxAirHumidity());// 空气湿度最大值

			jsonResponse
					.put("minSoilTemperature", app.getMinEarthTemperature());// 土壤温度最小值
			jsonResponse
					.put("maxSoilTemperature", app.getMaxEarthTemperature());// 土壤温度最大值
			jsonResponse.put("minSoilHumidity", app.getMinEarthHumidity());// 土壤湿度最小值
			jsonResponse.put("maxSoilHumidity", app.getMaxEarthHumidity());// 土壤湿度最大值

			jsonResponse.put("minLight", app.getMinLight());// 灯光强度最小值
			jsonResponse.put("maxLight", app.getMaxLight());// 灯光强度最大值
			jsonResponse.put("minCo2", app.getMinCo2());// CO2浓度最小值
			jsonResponse.put("maxCo2", app.getMaxCo2());// CO2浓度最大值

			jsonResponse.put("maxPM25", app.getMaxPm25());// PM2.5浓度最大值
			jsonResponse.put("controlAuto", app.getControlAuto());// 警告控制，0表示手动控制，1表示自动控制

			jsonResponse.put("result", "ok");
			logMsg = "Get threshold value of sensor";
			return jsonResponse.toString();
		} catch (JSONException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	protected String soapPorcess(String param) {
		String retSoapBody = "";
		ServerApp app = (ServerApp) context;
		retSoapBody = Util.getXmlElementStr("minAirTemperature",
				app.getMinAirTemperature() + "");// 空气温度最小值
		retSoapBody += Util.getXmlElementStr("maxAirTemperature",
				app.getMaxAirTemperature() + "");// 空气温度最大值
		retSoapBody += Util.getXmlElementStr("minAirHumidity",
				app.getMinAirHumidity() + "");// 空气湿度最小值
		retSoapBody += Util.getXmlElementStr("maxAirHumidity",
				app.getMaxAirHumidity() + "");// 空气湿度最大值

		retSoapBody += Util.getXmlElementStr("minSoilTemperature",
				app.getMinEarthTemperature() + "");// 土壤温度最小值
		retSoapBody += Util.getXmlElementStr("maxSoilTemperature",
				app.getMaxEarthTemperature() + "");// 土壤温度最大值
		retSoapBody += Util.getXmlElementStr("minSoilHumidity",
				app.getMinEarthHumidity() + "");// 土壤湿度最小值
		retSoapBody += Util.getXmlElementStr("maxSoilHumidity",
				app.getMaxEarthHumidity() + "");// 土壤湿度最大值

		retSoapBody += Util
				.getXmlElementStr("minLight", app.getMinLight() + "");// 灯光强度最小值
		retSoapBody += Util
				.getXmlElementStr("maxLight", app.getMaxLight() + "");// 灯光强度最大值
		retSoapBody += Util.getXmlElementStr("minCo2", app.getMinCo2() + "");// CO2浓度最小值
		retSoapBody += Util.getXmlElementStr("maxCo2", app.getMaxCo2() + "");// CO2浓度最大值

		retSoapBody += Util.getXmlElementStr("maxPM25", app.getMaxPm25() + "");// PM2.5浓度最大值
		retSoapBody += Util.getXmlElementStr("controlAuto",
				app.getControlAuto() + "");// 警告控制，0表示手动控制，1表示自动控制

		retSoapBody += Util.getXmlElementStr("result", "ok");
		logMsg = "Get threshold value of sensor";
		return Util.getSoapXml(retSoapBody);
	}

}
